/*
 * Copyright (c) 2016- 2020 qolome.com Inc. All Rights Reserved.
 * ProjectName: qolome-knowledge
 * FileName: QolomeMatchmaker.java
 * Author: jiangfeng@qolome.com
 * Date: 2020/3/3 下午1:14
 * LastModified: 2020/03/03 13:13:03
 */

package com.qolome.knowledge.design.pattern.proxy.demo.client;

import com.qolome.knowledge.design.pattern.proxy.demo.proxy.QolomeClassLoader;
import com.qolome.knowledge.design.pattern.proxy.demo.proxy.QolomeInvocationHandler;
import com.qolome.knowledge.design.pattern.proxy.demo.proxy.QolomeProxy;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Method;

/**
 * @author Qolome
 * @version V1.0
 * @Description 代理
 * @date 2020年 03月02日 22:19:23
 */
@Slf4j
public class QolomeMatchmaker implements QolomeInvocationHandler {

    private IPerson target;

    public IPerson getInstance(IPerson target) {
        this.target = target;
        Class<?> clazz = target.getClass();
        return (IPerson) QolomeProxy.newProxyInstance(new QolomeClassLoader(), clazz.getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object result = method.invoke(this.target, args);
        after();
        return result;
    }

    private void after() {
        log.info("双方同意开始交往");
    }

    private void before() {
        log.info("豪大大婚姻中介所,欢迎你的光顾");
    }
}
